package com.media_server.pojo;

import lombok.*;
import ws.schild.jave.EncoderException;
import ws.schild.jave.MultimediaObject;
import ws.schild.jave.info.MultimediaInfo;

import java.io.File;

@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString
@Builder
public class MediaDetail {
    private String bucket;  // 文件存储桶名
    private String objectName; // 文件存储路径
    private String url; // 文件访问路径
    private String originFileName;
    private String finalFileName;
    private long size;
    private String md5;
    private String contentType;
    private Long duration;  // 文件时长

    public static MediaDetail create(String bucket, String objectName, String url, String originFileName, String finalFileName, long size, String md5, String contentType, File path) throws EncoderException {
        // 获取文件时长 创建MultimediaObject
        MultimediaObject multimediaObject = new MultimediaObject(path);
        // 获取视频信息
        MultimediaInfo multimediaInfo = multimediaObject.getInfo();
        // 获取视频时长
        long duration = multimediaInfo.getDuration();
        return MediaDetail.builder()
                .bucket(bucket)
                .objectName(objectName)
                .url(url)
                .originFileName(originFileName)
                .finalFileName(finalFileName)
                .size(size)
                .md5(md5)
                .contentType(contentType)
                .duration(duration)
                .build();
    }
}
